package com.itheima.day12.ZuoYe.ZuoYe1;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ZuoYe1 {
    public static void main(String[] args) throws Exception {
        Map<Integer, User> map = new HashMap<>();
        SAXReader saxReader = new SAXReader();
        Document document = saxReader.read("D:\\javajc_ws\\javaEE\\src\\com\\itheima\\day12\\ZuoYe\\ZuoYe1\\ceshi.xml");
        Element rootElement = document.getRootElement();
        List<Element> elements = rootElement.elements("user");
        for (Element element : elements) {
        String name = element.elementText("name");
        String sex = element.elementText("sex");
        String adress = element.elementText("地址");
        String password = element.elementText("password");
        Element nameElement = element.element("name");
        int id = Integer.parseInt(element.attributeValue("id"));
            map.put(id, new User( name, sex, adress, password));
        }
        Set<Integer> keySet = map.keySet();
        for (Integer key : keySet) {
            User user = map.get(key);
            System.out.println(key+"---"+user);
        }

    }
}
